#ifndef _PARTSOURCE_HPP_
#define _PARTSOURCE_HPP_

#include "jhdefs.hpp"
#include "net/MessageHeader.hpp"
#include "stream/FileStream.hpp"
using JHCPP::stream::CFileInputStream;
#include <istream>
#include <string>

NET_NAMESPACE_BEGIN

class CPartSource
{
public:
	virtual std::istream& stream() = 0;
	virtual const std::string& filename() const;

	const std::string& mediaType() const;

	CMessageHeader& headers();
	const CMessageHeader& headers() const;

	virtual std::streamsize getContentLength() const;
	virtual ~CPartSource();

	static const int         UNKNOWN_CONTENT_LENGTH;
protected:
	CPartSource();
	CPartSource(const std::string& mediaType);

private:
	CPartSource(const CPartSource&);
	CPartSource& operator = (const CPartSource&);

	std::string		m_mediaType;
	CMessageHeader	m_headers;
};


class CFilePartSource : public CPartSource
{
public:
	CFilePartSource(const std::string& path);
	CFilePartSource(const std::string& path, const std::string& mediaType);
	CFilePartSource(const std::string& path, const std::string& filename, const std::string& mediaType);
	~CFilePartSource();

	std::istream& stream();
	const std::string& filename() const;
	std::streamsize getContentLength() const;

private:
	std::string			m_path;
	std::string			m_filename;
	CFileInputStream	m_istr;
};

NET_NAMESPACE_END

#endif
